package com.onejson.ojmall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onejson.ojmall.entity.TestEntity;
import com.onejson.ojmall.entity.dto.TestDTO;
import com.onejson.ojmall.entity.vo.TestVO;
import com.onejson.ojmall.mapper.TestMapper;
import com.onejson.ojmall.service.ITestService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 测试表
 *
 * @author 微信公众号 onejson
 * @date 2023-08-11
 */
@Service
@Transactional
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements ITestService {

    @Resource
    private TestMapper testMapper;


    /**
     * 查询测试表列表
     *
     * @param testEntity 测试表Entity类
     * @return 测试表
     */
    @Override
    public List<TestEntity> selectTestList(TestEntity testEntity) {
        return testMapper.selectTestList(testEntity);
    }

    /**
     * 新增测试表
     *
     * @param testDTO 测试表DTO类
     * @return 结果
     */
    @Override
    public boolean insertTest(TestDTO testDTO) {

        TestEntity testInfoEntity = new TestEntity();
        BeanUtils.copyProperties(testDTO, testInfoEntity);

        return this.save(testInfoEntity);
    }

    /**
     * 更新测试表
     *
     * @param testDTO 测试表DTO类
     * @return 结果
     */
    @Override
    public boolean updateTest(TestDTO testDTO) {

        TestEntity testInfoEntity = new TestEntity();
        BeanUtils.copyProperties(testDTO, testInfoEntity);

        return this.updateById(testInfoEntity);
    }


    /**
     * 详情测试表
     *
     * @param id id值
     * @return 结果
     */
    @Override
    public TestVO getTestById(Integer id) {

        TestEntity testEntity = this.getById(id);
        TestVO testVO = new TestVO();
        BeanUtils.copyProperties(testEntity, testVO);

        return testVO;
    }


    /**
     * 删除测试表
     *
     * @param ids id数组
     * @return 结果
     */
    @Override
    public boolean removeTestByIds(Integer[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }


}

